package com.dayaokeji.rhythmschoolstudent.client.home.course.ranking.adapter;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.exam.subject_type.utils.ScoreUtil;
import com.dayaokeji.server_api.domain.ScoringRankCourse;

/**
 * ********************************************************************
 * *  Created by Fei wo on 2018-12-5
 * ********************************************************************
 * *  version 1.0
 * ********************************************************************
 * *  Copyright (C) dayaokeji.com 2018 -- 2020 All rights reserved.
 * ********************************************************************
 * * course all list adapter
 * ********************************************************************
 */
public class CourseAllListAdapter  extends BaseQuickAdapter<ScoringRankCourse,BaseViewHolder> {

    public CourseAllListAdapter() {
        super(R.layout.item_course_time_list);
    }

    @Override
    protected void convert(BaseViewHolder helper, ScoringRankCourse item) {
        TextView tvCourseScore = helper.getView(R.id.tv_course_score);
        String score = item.getScore() == null ? "--" : String.valueOf(ScoreUtil.doubleTrans(item.getScore()));
        SpannableString spannableString = new SpannableString(score+" 分");
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.6F);
        spannableString.setSpan(sizeSpan, 0, spannableString.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvCourseScore.setText(spannableString);
        String actStartTime = item.getActStartTime();
        String[] split = actStartTime.split(" ");
        if (split.length == 2) {
            String ymd = split[0];
            String time = split[1];

            helper.setText(R.id.tv_course_start_time, time)
                    .setText(R.id.tv_course_address, item.getRoomName())
                    .setText(R.id.course_time, ymd)
                    .addOnClickListener(R.id.cl_course);
        }

    }
}
